﻿/***********************************************************************************************
 * 
 * ProjectName: WMSSoft.Lib.WinKStart
 * 
 * Description: Provide properties to define a Datasource
 * 
 * Created:     21.07.2014
 * 
 * Author:      matthias wagler - matthias@WMSSoft.de
 * 
 * Copyright:   Copyright 2014 by WMSSoft.de
 * 
 * License:     GPLv3
 * 
 * History:     21.07.2014 - matthias wagler matthias@WMSSoft.de   -   Created
 * 
 **********************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WMSSoft.Lib.Basic;
using WMSSoft.Lib.Interfaces;
using WMSSoft.Lib.WinKStart.Abstract;

namespace WMSSoft.Lib.WinKStart.Model.MenuConfig
{
    [Serializable()]
    public class DataSource : CModelBase
    {
        private string _Name = "";
        private string _Assembly = "";
        private string _ClassName = "";
        private string _ShortName = "";
        private long _LastUpdated = 0;
        private bool _Searchable = false;
        private iWinKStartDataSource _InstanceDataSource = null;
        private List<iWinKStartItem> _Items = new List<iWinKStartItem>();
        private Dictionary<string, KeyValueAssignment> _Assignments = new Dictionary<string, KeyValueAssignment>();
        private Dictionary<string, KeyValueAssignment> _Options = new Dictionary<string, KeyValueAssignment>();

        public DataSource() { }

        public DataSource(string Name, string Assembly, String ClassName)
        {
            _Name = Name;
            _Assembly = Assembly;
            _ClassName = ClassName;
        }

        /// <summary>
        /// Contains the DataSource unique Name, will be used to access to Data from this Datasource
        /// </summary>
        public string Name
        {
            get { return _Name; }
            set 
            { 
                _Name = value;
                OnPropertyChanged();
            }
        }

        /// <summary>
        /// Contains the Assembly filename in this the datasource is defined
        /// </summary>
        public string Assembly
        {
            get { return _Assembly; }
            set 
            { 
                _Assembly = value;
                OnPropertyChanged();
            }
        }

        /// <summary>
        /// Contains the Name of the Class that create/ read the data
        /// </summary>
        public string ClassName
        {
            get { return _ClassName; }
            set 
            { 
                _ClassName = value;
                OnPropertyChanged();
            }
        }

        /// <summary>
        /// Contains the Name to view in settings page if the datasource
        /// is searchable
        /// </summary>
        public string ShortName
        {
            get { return _ShortName; }
            set 
            { 
                _ShortName = value;
                OnPropertyChanged();
            }
        }

        /// <summary>
        /// If true the DataSource is viewed in settingspage to select for searching
        /// </summary>
        public bool Searchable 
        {
            get { return _Searchable; }
            set 
            { 
                _Searchable = value;
                OnPropertyChanged();
            } 
        }

        public long LastUpdate
        {
            get { return _LastUpdated; }
            set 
            { 
                _LastUpdated = value;
                OnPropertyChanged();
            }
        }

        /// <summary>
        /// Instance from bounded assembly class
        /// </summary>
        public iWinKStartDataSource InstanceDataSourceItem
        {
            get { return _InstanceDataSource; }
            set 
            { 
                _InstanceDataSource = value;
                OnPropertyChanged();
            }
        }

        /// <summary>
        /// Manual added Datasets
        /// </summary>
        public List<iWinKStartItem> Items
        {
            get { return _Items; }
        }

        public List<KeyValueAssignment> Extensions
        {
            get
            {
                return _Assignments.Values.ToList();
            }           
        }

        public List<KeyValueAssignment> Options
        {
            get
            {
                return _Options.Values.ToList();
            }
        }

        /// <summary>
        /// Contains all file extension to filter links
        /// </summary>
        public Dictionary<string, KeyValueAssignment> ExtensionsDict
        {
            get { return _Assignments; }
            set 
            { 
                _Assignments = value;
                OnPropertyChanged();
            }
        }

        /// <summary>
        /// Contains all Settings for this DataSource
        /// </summary>
        public Dictionary<string, KeyValueAssignment> OptionsDict
        {
            get { return _Options; }
            set 
            { 
                _Options = value;
                OnPropertyChanged();
            }
        }
    }
}
